let passport = require('passport')
let LinkedInStrategy = require('passport-linkedin-oauth2').Strategy
let config = require('../_config')

passport.use(new LinkedInStrategy({
  clientID: config.linkedin.clientID,
  clientSecret: config.linkedin.clientSecret,
  callbackURL: config.linkedin.callbackURL,
  scope: ['r_emailaddress', 'r_basicprofile'],
  passReqToCallback: true
}, function(req, accessToken, refreshToken, profile, done) {
  // asynchronous verification, for effect...
  process.nextTick(function () {
    //在这里你可以对profile进行处理，比如进行存储或者方便
    if(req.user){
      //...绑定
      // app.db.models.User.findOne({...},function(){
      //     ....
      // })
    }
    else {
        //...新建一个用户
        // var user = new app.db.models.User();
        // user.github = profile;
        // user.save();
    }
    //...或者存储accessToken

    return done(null, profile);
  });
}));

module.exports = passport